package pl.wroc.uni.ii.puzzle.game;

import pl.wroc.uni.ii.puzzle.R;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.test.AndroidTestCase;
import android.util.DisplayMetrics;

public class CellTest extends AndroidTestCase {

	private Cell cell;

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		Context context = getContext();
		final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
		Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.sharapova1);
		bitmap = Bitmap.createScaledBitmap(bitmap, metrics.widthPixels, metrics.heightPixels, true);

		int rows = Game.ROWS_COUNT_EASY;
		int columns = Game.COLUMNS_COUNT_EASY;
		int row = 1;
		int column = 1;
		cell = new Cell(row, column, metrics.widthPixels/columns, metrics.heightPixels/rows, bitmap);
	}

	@Override
	protected void tearDown() throws Exception {
		super.tearDown();
	}

	public void testSwitchSelection() {
		//given
		assertFalse(cell.isSelected());
		
		//when
		cell.switchSelection();
		
		//then
		assertTrue(cell.isSelected());
	}
	
	public void testSwitchSelection2() {
		//given
		assertFalse(cell.isSelected());
		
		//when
		cell.switchSelection();
		cell.switchSelection();
		
		//then
		assertFalse(cell.isSelected());
	}
	
	public void testSwitchSelection3() {
		//given
		assertFalse(cell.isSelected());
		
		//when
		cell.switchSelection();
		cell.switchSelection();
		cell.switchSelection();
		
		//then
		assertTrue(cell.isSelected());
	}

	public void testReflectHorizontal() {
		//given
		assertTrue(cell.isInProperPosition());
		
		//when
		cell.reflectHorizontal();
		
		//then
		assertFalse(cell.isInProperPosition());
	}
	
	public void testReflectHorizontal2() {
		//given
		assertTrue(cell.isInProperPosition());
		
		//when
		cell.reflectHorizontal();
		cell.reflectHorizontal();
		
		//then
		assertTrue(cell.isInProperPosition());
	}
	
	public void testReflectHorizontal3() {
		//given
		assertTrue(cell.isInProperPosition());
		
		//when
		cell.reflectHorizontal();
		cell.reflectHorizontal();
		cell.reflectHorizontal();
		
		//then
		assertFalse(cell.isInProperPosition());
	}

	public void testReflectVertical() {
		//given
		assertTrue(cell.isInProperPosition());
		
		//when
		cell.reflectVertical();
		
		//then
		assertFalse(cell.isInProperPosition());
	}
	
	public void testReflectVertical2() {
		//given
		assertTrue(cell.isInProperPosition());
		
		//when
		cell.reflectVertical();
		cell.reflectVertical();
		
		//then
		assertTrue(cell.isInProperPosition());
	}
	
	public void testReflectVertical3() {
		//given
		assertTrue(cell.isInProperPosition());
		
		//when
		cell.reflectVertical();
		cell.reflectVertical();
		cell.reflectVertical();
		
		//then
		assertFalse(cell.isInProperPosition());
	}

	public void testReflectVerticalAndHorizontal() {
		//given
		assertTrue(cell.isInProperPosition());
		
		//when
		cell.reflectVertical();
		cell.reflectHorizontal();
		
		//then
		assertFalse(cell.isInProperPosition());
	}
	
	public void testReflectVerticalAndHorizontal2() {
		//given
		assertTrue(cell.isInProperPosition());
		
		//when
		cell.reflectVertical();
		cell.reflectHorizontal();
		cell.reflectVertical();
		cell.reflectHorizontal();
		
		//then
		assertTrue(cell.isInProperPosition());
	}
	
	public void testReflectVerticalAndHorizontal3() {
		//given
		assertTrue(cell.isInProperPosition());
		
		//when
		cell.reflectVertical();
		cell.reflectHorizontal();
		cell.reflectHorizontal();
		cell.reflectHorizontal();
		
		//then
		assertFalse(cell.isInProperPosition());
	}

}
